<?php

include ('main.php');

class filtros_check extends filtros{

	function check_get_where_clause($selected_filter=''){
		$return_string = " ";
		foreach ($this->filters_list as $filter){
			if ($filter['field_denomination'] != $selected_filter && $filter['selected'] == true){
				switch($filter['filter_type']){
					case 'text' 		: $return_string .= 'AND ' . $filter['id_field_on_table'] . ' like "%' . $filter['selected_value'] . '%" '; break;
					case 'items_list' 	: 
						$selected_values_string = '"' . implode('","',$filter['selected_value']) . '"';
						$return_string .= 'AND ' . $filter['id_field_on_table'] . ' IN (' . $selected_values_string . ') '; 
						break;
					case 'range' 		: 
						if ($filter['selected_value']['min'] != ""){
							$return_string .= 'AND ' . $filter['id_field_on_table'] . ' >= ' . $filter['selected_value']['min'] . ' ';
						};
						if ($filter['selected_value']['max'] != ""){
							$return_string .= 'AND ' . $filter['id_field_on_table'] . ' <= ' . $filter['selected_value']['max'] . ' ';
						};
						break;
				}
			}
		}
		return $return_string . ' AND ' . $this->campo_precio . ' != "" ';
	}
	
	function check_complete_url_on_remove($parametros,$url_den,$additional_filters_string,$filtros_adicionales){
		foreach ($this->filters_list as $current_key => $current_filter){
			$field_denomination = $current_filter['field_denomination'];
			if ($current_filter['selected'] ){
				$this->filters_list[$current_key]['url_on_remove'] 	= $this->get_filter_url($url_den,$current_filter['field_denomination'],$additional_filters_string);
			}
		}
	}

	function check_create_items_lists($url_den,$additional_filters_string){
		foreach ($this->filters_list as $current_key => $current_filter){
			if ($current_filter['filter_type'] == 'items_list'){
				$list = $this->get_items_list($current_filter);
				foreach($list as $item){
					$checked = false;
					if (in_array($item['value'],$current_filter['selected_value'])){
						$checked = true;
					}
					$precio_minimo = '';
					if (isset($item['precio_minimo'])){
						$precio_minimo = $item['precio_minimo'];
					}
					$this->filters_list[$current_key]['items_list'][] = array(
						'check_display_text' 	=> $this->get_display_value($current_key,$item['value'],$item['display_value'],$current_filter['check_display_text']),
						//'check_display_text' 	=> str_replace('<value>',$item['value'],$current_filter['check_display_text']),
						'url' 		=> $this->get_filter_url($url_den,$current_key,$item['value'],$additional_filters_string),
						'value' 	=> $item['value'],
						'quantity' 	=> $item['cantidad'],
						'min_price'	=> $precio_minimo,
						'checked' 	=> $checked
					);
				}
			}
		}
	}
}
?>